/* @INLINE FILE format_msgs.bloc.js =============================================================
	* Format the chat msgs for display
	* 
	* VAR
	* 
	* FUNC
	* cdt - format the date
	* myUn - main format function
	* myUn2
    * myUn3
	*/
	
    var cdt = function(d,m,k) {
        d = d - 0;
        var theDate = new Date(d);
        var now = new Date();
        var diff = now.getTime()-d;
        var ago = div(diff,60000);
        var mins = ago;
        var val='';
        if(m=='1'||(k&&mins>1440)){
	        if(ago<60){
	        	var _bef=__(136);
	        	var _aft=__(138);
	        	if(ago!=1){
	        		_bef=__(137);
		        	_aft=__(139);
	        	}
	        	if(ago>=1){
	        		val = " ("+ _bef + ago + _aft +")";
	        	}else{
	        		val = " ("+__(148)+")";
	        	}
	        }else{
	        	ago = div(diff,3600000);
	            if(ago>=1 && ago<24){
	            	var _bef=__(140);
		        	var _aft=__(142);
		        	if(ago!=1){
		        		_bef=__(141);
			        	_aft=__(143);
		        	}
		        	val = " ("+ _bef + ago + _aft +")";
	            }else{
	            	ago = div(diff,86400000);
	            	var _bef=__(144);
		        	var _aft=__(146);
		        	if(ago!=1){
		        		_bef=__(145);
			        	_aft=__(147);
		        	}
		        	val = " ("+ _bef + ago + _aft +")";
	            }
	        }
        }
        if(ts == 'display:inline'||(k&&mins<=1440)){
	        var ap = __(149);
	        var hour = theDate.getHours();
	        if (hour > 11) {
	            ap = __(150);
	        }
	        if (hour > 12) {
	            hour = hour - 12;
	        }
	        if (hour == 0) {
	            hour = 12;
	        }
	        if (theDate.getMinutes() >= 10) {
	            return(val + '( ' + hour + ':' + theDate.getMinutes() + ap + ')');
	        } else {
	            return(val + ' (' + hour + ':0' + theDate.getMinutes() + ap + ')');
	        }
        }else{
        	return val;
        }
    };
    
    var myUn =  function(msg,im,k,n,controlled) {
    	//for forced private messages
    	if(msg.substring(0,2)=='%%'){
    		msg=msg.substr(2);
    		controlled=1;
    	}
        var tx = [];
        tx[0] = __(37);
        tx[1] = __(38);
        tx[2] = __(39);
        var tx1 = [];
        tx1[0] = "strong";
        tx1[1] = "i";
        tx1[2] = "u";
        if(msg.indexOf('%a')!=-1){
        	msg=msg.replace(/%a/g, '<a').replace(/%~a/g, '</a>').replace(/%g/g, '>').replace(/%i/g, '<img').replace(/%d/g, '<div').replace(/%~d/g, '</div>');
        }
        msg = msg.replace(/%26/g, '&').replace(/%25/g, '%');
        for (var j = 0; j < 3; j ++ ) {
            var m1 = msg.split(tx[j]);
            if (m1.length > 1) {
                msg = '';
                var m2 = '</' + tx1[j] + '>';
                for (var i = m1.length - 1; i >= 0; i -- ) {
                    msg = m2 + m1[i] + msg;
                    m2 = (m2 == '</' + tx1[j] + '>' ? '<' + tx1[j] + ((j==0)?' style="font-weight:bold;"':'') + '>': '</' + tx1[j] + '>');
                }
            }
        }
        var mP = 0;
        var mPO = 0;
        var mPN = 0;
        var mPN2 = 0;
        var imgC = 0;
        var wdt = '';
        var dsp = 'display:inline;';
        var fbr = '<br>';
        var jxt = false;
        if (im == 0) {
            wdt = 'width:' + (EN(private_chat_panel.style.width) + 11) + 'px';
            dsp = ''
        }
        while (true) {
            mP = msg.indexOf('[[');
            if (mP !=- 1 && mP >= mPO) {
                mPO = mP;
                mP = msg.indexOf(']]');
                if (mP !=- 1 && mP >= mPO) {
                    var img = msg.substring(mPO + 2, mP);
                    var img2 = img.replace(/'/g, '\\\'');
                    if (smls[img2] != null) {
                        msg = msg.replace('[[' + img + ']]', '<div style="display:inline;background-color:transparent;height:' + smlsHt[img2] + 'px;">'+add_spacer(smlsHt[img2])+'<img border="0" height="' + smlsHt[img2] + 'px" src="' + config.smileys_dir + smls[img2] + '">&nbsp;</div>');
                    } else if (imgC < 3) {
                        var img2 = img;
                        img = img.replace(/%/g, '%25');
                        var imgdir = _ttt;
                        if(img.indexOf("/")>=0){
                        	img=img.substr(img.indexOf('_')+1);
                        	if(!config.allow_crossdomain_images){
                            	if(url_domain(img).indexOf('fastcatsoftware.com')<0&&url_domain(img).indexOf(config.current_domain)<0){
                            		img="";
                            	}
                            }
                        	imgdir='';
                        }
                        if ( ! jxt) {
                            msg = msg.replace('[[', fbr+'<div style="'+dsp+'background-color:transparent;height:42px;' + wdt + '">'+add_spacer(42)+'<a href="' + imgdir + img + '" target="_blank"><img alt="'+__(406,"Image")+'" style="margin-top:2px;" border="0" height="40px" src="' + imgdir);
                            mPN = msg.indexOf(']]');
                            mPN2 = msg.indexOf('[[');
                            msg = msg.replace(img2 + ']]', img + '"></a></div>');
                        }
                        imgs = 1;
                        dsp = 'display:inline;';
                        wdt = '';
                        fbr = '';
                        imgC ++ ;
                    }
                    mPO = mP;
                } else {
                    break;
                }
            } else {
                break;
            }
        }
        if(controlled==1){
        	msg=myUn2(msg);
        }
        if(translator.on==1&&k){
	        var txt = msg;
	        var id = (k==6?'fc_gm':'fc_pm')+n+'t';
	        if(k==8){id='fc_tm'+n+'t'};
	        mP=0;
	        mPO=0;
	        /*
	        while (true) {
	            mP = txt.indexOf('<div');
	            if (mP !=- 1 && mP >= mPO) {
	                mPO = mP;
	                mP = txt.indexOf('div>');
	                if (mP !=- 1 && mP >= mPO) {
	                    txt = txt.substring(0, mPO)+txt.substr(mP+4);
	                }else{
	                	break;
	                }
	            }else{
	            	break;
	            }
	        }
	        */
	        while (true) {
	        	mP = txt.indexOf('<');
	            if (mP !=- 1 && mP >= mPO) {
	                mPO = mP;
	                mP = txt.indexOf('>');
	                if (mP !=- 1 && mP >= mPO) {
	                    txt = txt.substring(0, mPO)+txt.substr(mP+1);
	                }else{
	                	break;
	                }
	            }else{
	            	break;
	            }
	        }
	        txt=txt.replace(/&nbsp;/gi,"");
	        msg +="<span style='font-style:italic' id='"+id+"'></span>";
	        translate(txt,id,k);
        }
        if(controlled==1){
        	msg=myUn3(msg);
        }
        return msg;
    };
    
    var myUn2 = function(msg){
    	var mPO;
    	var mP=-1;
        while((mP=msg.indexOf('{{!*',mP+1))!=-1){
        	mPO = msg.indexOf('*!}}',mP);
        	if(mPO!=-1){
        		msg=msg.substring(0,mP)+__(EN(msg.substring(mP+4,mP+10)),msg.substring(mP+10,mPO))+msg.substring(mPO+4,msg.length);
        	}
        }
        return msg;
    };
    
    var myUn3 = function(msg){
    	var mPO;
    	var mP=-1;
    	mP = msg.indexOf('{{');
        if (mP !=- 1) {
            mPO = msg.indexOf('}}');
            if (mPO >= mP) {
            	var _room = (EN(msg.substring(mP + 2, mPO))!=0?rooms[EN(msg.substring(mP + 2, mPO))].nm:'none');
                msg=msg.substring(0,mP)+_room+msg.substring(mPO+2,msg.length);
            }
        }
        return msg;
    };
    
    //format_msgs.bloc.js =============================================================@END FILE*/